package edu.xhu;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class AboutActivity extends Activity{

	private Button mBtnBack;
	
	private ImageView mLogoImageView;
	private TextView mAbouTextView, mProTextView, mWebTextView;
	
	private Timer timer;
	private TimerTask task;
	
	private long timeDelay = 4000;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.about_us);
		
		initView();
		setListener();
				
		timer = new Timer();
		task = new TimerTask() {
			@Override
			public void run() {
				mLogoImageView.post(new Runnable() {
					public void run() {
						Animation shake = AnimationUtils.loadAnimation(AboutActivity.this, R.anim.shake);
						mLogoImageView.startAnimation(shake);
					}
				});
			}
		};
		
		timer.schedule(task, timeDelay, timeDelay);
	}
	
	private void initView(){
		mBtnBack = (Button) findViewById(R.id.button_back);
		mLogoImageView		= (ImageView) findViewById(R.id.logo);
		mAbouTextView		= (TextView) findViewById(R.id.textview_about);
		mProTextView		= (TextView) findViewById(R.id.textview_our_product);
		mWebTextView		= (TextView) findViewById(R.id.textview_website);
	}
	
	private void setListener(){
		mBtnBack.setOnClickListener( new OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(AboutActivity.this, XihuaClientActivity.class);
				setResult(RESULT_OK, intent);
				finish();
				overridePendingTransition(R.anim.slide_up_in, R.anim.slide_down_out);
			}
		});
	}
	
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			Intent intent = new Intent(AboutActivity.this, XihuaClientActivity.class);
			setResult(RESULT_OK, intent);
			finish();
			overridePendingTransition(R.anim.slide_up_in, R.anim.slide_down_out);
			return false;
		}
		return false;
	}

	@Override
	protected void onDestroy() {
		task.cancel();
		timer.cancel();
		
		super.onDestroy();
	}
	
	
}
